<!-- 康复救助详情 -->
<template>
  <el-card class="app-container">
    <el-descriptions title="基本信息" :column="2" border>
      <el-descriptions-item label="康复救助对象">{{currentData.recoveryName}}</el-descriptions-item>
      <el-descriptions-item label="年龄">{{currentData.recoveryAge}}</el-descriptions-item>
      <el-descriptions-item label="身份证号">{{currentData.recoveryCard}}</el-descriptions-item>
      <el-descriptions-item label="救助类型">
        <el-tag size="small">{{currentData.recoveryTypeName}}</el-tag>
      </el-descriptions-item>
      <el-descriptions-item label="监护人姓名">{{currentData.guardianName}}</el-descriptions-item>
      <el-descriptions-item label="监护人联系方式">{{currentData.guardianPhone}}</el-descriptions-item>
      <el-descriptions-item label="状态">
        <el-tag size="small">{{currentData.status | keyText("etkfjzzt")}}</el-tag>
      </el-descriptions-item>
      <el-descriptions-item label="救助机构">
        {{ currentData.applyUserName }}
      </el-descriptions-item>
      <el-descriptions-item label="开始时间">
        {{ currentData.createTime | formatTime("yyyy-MM-dd") }}
      </el-descriptions-item>
      <el-descriptions-item label="结束时间">
        {{ currentData.recoveryEndTime | formatTime("yyyy-MM-dd") }}
      </el-descriptions-item>
      <el-descriptions-item label="家庭住址" span="2">
        {{currentData.address}}
      </el-descriptions-item>

      <el-descriptions-item v-for="(item,index) in files" :key="index" :label="item">
        <el-image
          style="width: 150px;height: 150px"
          :src="getImage(currentData.files.split(',')[index])"
          :preview-src-list="[getImage(currentData.files.split(',')[index])]"
        />
      </el-descriptions-item>
      <!--      <el-descriptions-item label="相关证明文件">-->
      <!--        <div style="display: inline-block">-->
      <!--          <div v-for="(item, index) in JSON.parse(currentData.files)" :key="index" style="margin-bottom: 4px">-->
      <!--            <a class="article_title_a" @click="previewDetail(item.id)">{{ item.fileName }}</a>-->
      <!--          </div>-->
      <!--        </div>-->
      <!--      </el-descriptions-item>-->
    </el-descriptions>
    <div class="btn-box">
      <template v-if="currentData.status==='CL_APPLY' && $route.query.type==='apply'">
        <el-button icon="el-icon-check" type="success" class="mr10" @click="handleAudit('INSTITUTE_APPLY')">残联审核通过</el-button>
        <el-button icon="el-icon-close" type="danger" class="mr10" @click="handleAudit('CL_REJECT')">残联驳回</el-button>
      </template>
      <!--      <template v-if="currentData.status==='INSTITUTE_APPLY' && $route.query.type==='mechanism'">-->
      <!--        <el-button icon="el-icon-check" type="success" class="mr10" @click="handleAudit('INSTITUTE_APPLY')">康复机构审核通过-->
      <!--        </el-button>-->
      <!--        <el-button icon="el-icon-close" type="danger" class="mr10" @click="handleAudit('CL_REJECT')">康复机构驳回-->
      <!--        </el-button>-->
      <!--      </template>-->
      <el-button @click="$router.go(-1)">返回</el-button>
    </div>
  </el-card>
</template>
<script>
export default {
  name: 'RecoveryDetail',
  data() {
    return {
      currentData: {},
      files: [
        '备案表（加章）',
        '诊断证明',
        '协议书（加章）',
        '户主与华子户口本',
        '监护人身份证或户口',
        '照片（儿童）'
      ]
    }
  },
  methods: {
    //点击预览
    previewDetail(val) {
      this.openTabPage(
        window.api.preFile +
        "?url=" +
        window.api.secretFilePreview +
        val +
        "?token=" +
        window.sessionStorage.getItem("token")
      );
    },
    getImage(url) {
      return window.api.image + '/' + url
    },

    getData() {
      const { id } = this.$route.query
      this.API.getRecoveryById({ id }).then(ret => {
        this.currentData = ret.data;
      });
    },

    // 审核
    handleAudit(status) {
      this.$confirm("确定要执行审核操作吗？", "提示", {}).then(() => {
        const body = Object.assign({}, this.currentData, { status })
        this.API.addOrUpdateRecovery({ body }).then(res => {
          this.success('审核成功');
          this.$router.go(-1);
        }).catch(err => {
          this.error(err)
        })
      }).catch(() => {
      })
    }
  },
  mounted() {
    this.getData()
  }
}
</script>
<style scoped lang="scss">
  .app-container {
    padding: 20px;

    .btn-box {
      margin-top: 50px;
      text-align: center;
    }
  }
</style>
